package com.tang.algorithm.swordFingerOffer;

/**
 * @author tlm
 * @version 1.0
 * @date 2020/5/7 20:17
 * 机器人的运动范围
 * <p>
 * https://leetcode-cn.com/problems/ji-qi-ren-de-yun-dong-fan-wei-lcof/
 */
public class RobotRangeOfMotion {

    int m, n, k;
    boolean[][] map;

    public static void main(String[] args) {
        RobotRangeOfMotion r = new RobotRangeOfMotion();
        System.out.println(r.movingCount(2, 3, 1));
        System.out.println(r.isMoreK(0, 1));
    }
    public int movingCount(int m, int n, int k) {
        this.m = m;
        this.n = n;
        this.k = k;
        this.map = new boolean[m][n];
        System.out.println("k"+k);
        return dfs(0,0);

    }

    public  int dfs(int i, int j) {
        if(i>=m|| j>=n||isMoreK(i,j)||map[i][j]) {
            return 0;
        }
        map[i][j]=true;
        return 1+dfs(i+1,j)+dfs(i,j+1);
    }

    /**
     * 判断行坐标和列坐标的数位之和是否大于k
     *
     * @param m 行坐标
     * @param n 列坐标
     *
     * @return
     */
    public  boolean isMoreK(int m, int n) {

        int mSum = 0, nSum = 0;
        while (m != 0) {
            mSum += +m % 10;
            m = m / 10;
        }
        while (n != 0) {
            nSum += n % 10;
            n = n / 10;
        }
        return (nSum + mSum) > k;
    }

}
